<template>
	<view class="home">

		<view v-if="list.length==0">
			<u-empty mode="message" icon="http://cdn.uviewui.com/uview/empty/message.png">
			</u-empty>
		</view>

		<scroll-view scroll-y v-else @scrolltolower="bottomingOut" style="height: 100%;">
			<view class="home-box" v-for="(item,index) in list" :key="index" @click="getInChat(item)">
				<view class="box-left">
					<view>
						<image src="@/static/image/doctor.jpg" mode=""></image>
					</view>
					<view class="left-title">
						<view style="font-size: 26rpx;font-weight: bold;color: #333;">医生-{{item.realName}}</view>
						<view>
							<u-parse :lazyLoad="true" v-show="item.msgContent.includes('emoji')">
								[表情]
							</u-parse>
							<u-parse :lazyLoad="true" v-show="!item.msgContent.includes('emoji')"
								:content="item.msgType===1?item.msgContent:item.msgType===2?'[语音]':'[图片]'"></u-parse>
						</view>
					</view>
				</view>
				<view class="box-right"
					style="display: flex;justify-content: space-between;flex-direction: column;align-items: flex-end;">
					<view>
						{{item.createTime}}
					</view>
					<view style="margin-bottom: 20rpx;">
						<u-badge type="success" max="99" :value="item.readCount"></u-badge>
					</view>
				</view>

			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: []
			};
		},
		onShow() {
			this.getList()
		},
		methods: {
			//查询消息列表
			async getList() {
				const {
					data
				} = await uni.$http.post('/chatMessage/findFriendToMsg')
				if (data.code === 200) {
					this.list = data.data.msgList
				}
			},
			//触底
			bottomingOut() {
				console.log(123);
			},
		}
	}
</script>

<style lang="scss">
	.home {
		width: 100%;
		height: 100%;
		background-color: #f2f2f2;
		padding: 20rpx;
		box-sizing: border-box;

		.home-box {
			margin-bottom: 20rpx;
			width: 100%;
			background-color: #fff;
			border-radius: 20rpx;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			align-items: stretch;
			justify-content: space-between;

			.box-left {
				width: 70%;
				display: flex;
				align-items: stretch;
				justify-content: flex-start;

				image {
					width: 100rpx;
					height: 100rpx;
					border-radius: 10rpx;
					overflow: hidden;
				}

				.left-title {
					margin-left: 20rpx;
					display: flex;
					flex-direction: column;
					align-items: flex-start;
					justify-content: space-around;
				}
			}

			.box-right {
				width: 30%;
				display: flex;
				align-items: flex-start;
				justify-content: center;
			}
		}
	}
</style>